@if(isset($dataTypeContent->{$row->field}) && !is_null(old($row->field, $dataTypeContent->{$row->field})))
    <?php $selected_value = old($row->field, $dataTypeContent->{$row->field}); ?>
@else
    <?php $selected_value = old($row->field);?>
@endif
<?php
        if(isset($options->level)){
            $parentBoolean = isset($options->parent)&&$options->parent;
            $parentSelectAndExist = $parentBoolean&&(isset($dataTypeContent->{$options->parent})&&$dataTypeContent->{$options->parent});
            switch ($options->level){
                case 1:
                    $parentId = 0;
                  break;
                case 2:
                    if(!$parentBoolean){
                        echo '<p class="label label-warning"><i class="voyager-warning"></i> 缺少parent参数或者未设置parent</p>';
                        $parentId = 0;

                    }else{
                        $parentId = $parentSelectAndExist?$dataTypeContent->{$options->parent}:110001;
                    }
                    break;
                case 3:
                    if(!$parentBoolean){
                        echo '<p class="label label-warning"><i class="voyager-warning"></i> 缺少parent参数或者未设置parent</p>';
                        $parentId = 0;

                    }else{
                        $parentId = $parentSelectAndExist?$dataTypeContent->{$options->parent}:110000;
                    }
                    break;
                default:
                    $parentId = 0;
                    break;
            }
        }else{
            $options->level = 1;
            $parentId = 0;
        }
        $areaList = \App\Area::where('parent_id',$parentId)->get();
?>
<select class="form-control select2" name="{{$row->field}}" id="area-{{$row->field}}">
@if(isset($areaList)&&$areaList)
    @foreach($areaList as $area)
    <option value="{{trim($area->area_id)}}" @if($selected_value==$area->area_id)selected @endif>{{trim($area->area_name)}}</option>
    @endforeach
@endif
</select>
<script>
    @if($options->level==2||$options->level==3)
    $(function () {
        var $areaRequestUrl = "{{url('api/cascade/area')}}"
        $(document).on('change','#area-{{$options->parent}}',function () {
            var $parentId;
            $parentId = $(this).val();
            $.post(
                $areaRequestUrl,
                {
                    'parentId':$parentId
                },
                function (e) {
                    if(e.status==1){
                        str = '';
                        for(var i in e.list){
                            str += '<option value='+e.list[i].area_id+'>';
                            str += e.list[i].area_name.trim();
                            str += '</option>';
                        }
                        $('#area-{{$row->field}}').html(str).trigger('change');
                    }else{
                        toastr.error('网络错误');
                    }
                },
                'json'
            )
        })
    })
    @endif
</script>